package com.spark.market.dal.repository.impl;

import com.spark.market.common.utils.AssertUtils;
import com.spark.market.dal.dao.ItemDoMapper;
import com.spark.market.dal.entity.ItemDo;
import com.spark.market.dal.repository.ItemRepository;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class ItemRepositoryImpl implements ItemRepository {
    @Resource
    private ItemDoMapper itemDoMapper;
    @Override
    public List<ItemDo> selectAllItem() {
        return itemDoMapper.selectAll();
    }

    @Override
    public void insertItem(ItemDo itemDo) {
        AssertUtils.isNotNull(itemDo, "itemDo is null");
        itemDoMapper.insertSelective(itemDo);
    }

    @Override
    public ItemDo selectItemById(Integer id) {
        AssertUtils.isNotNull(id, "id is null");
        return itemDoMapper.selectByPrimaryKey(id);
    }

    @Override
    public void increaseSales(Integer itemId, Integer amount) {
        AssertUtils.isNotNull(itemId, "itemId is null");
        AssertUtils.isNotNull(amount, "amount is null");
        itemDoMapper.increaseSalesByItemId(itemId,amount);
    }
}
